<?php
/*********************/
/*                   */
/*  后台积分历史模块       */
/*   BY voiet        */
/*   2009-9-19更新    */
/*                   */
/*********************/
//require_once( CORE_DIR."/model/trading/mdl.memberpoint.php" );
class cmd_pointhistory extends mdl_pointhistory
{
	function gethistoryreason( )
	{
		$aHistoryReason = array(
			"order_pay_use" => array(
				"describe" => __( "订单消费积分" ),
				"type" => 1,
				"related_id" => "sdb_mall_orders"
			),
			"order_pay_get" => array(
				"describe" => __( "订单获得积分." ),
				"type" => 2,
				"related_id" => "sdb_mall_orders"
			),
			"order_refund_use" => array(
				"describe" => __( "退还订单消费积分" ),
				"type" => 1,
				"related_id" => "sdb_mall_orders"
			),
			"order_refund_get" => array(
				"describe" => __( "扣掉订单所得积分" ),
				"type" => 2,
				"related_id" => "sdb_mall_orders"
			),
			"order_cancel_refund_consume_gift" => array(
				"describe" => __( "Score deduction for gifts refunded for order cancelling." ),
				"type" => 1,
				"related_id" => "sdb_mall_orders"
			),
			"exchange_coupon" => array(
				"describe" => __( "兑换优惠券" ),
				"type" => 3,
				"related_id" => ""
			),
			"operator_adjust" => array(
				"describe" => __( "管理员改变积分." ),
				"type" => 3,
				"related_id" => ""
			),
			"recommend_mem" => array(
				"describe" => __( "推荐用户获得积分." ),
				"type" => 4,
				"related_id" => ""
			),
			"recommend_pifa" => array(
				"describe" => __( "推荐用户成为代理获得积分." ),
				"type" => 5,
				"related_id" => ""
			),
			"recommend_order" => array(
				"describe" => __( "推荐用户订单获得积分." ),
				"type" => 6,
				"related_id" => ""
			),
			"register_mem" => array(
				"describe" => __( "注册会员获得积分." ),
				"type" => 7,
				"related_id" => ""
			),
			"consume_gift" => array(
				"describe" => __( "积分换赠品." ),
				"type" => 8,
				"related_id" => "sdb_mall_orders"
			)
		);
		return $aHistoryReason;
	}
	
	function addhistory( $aData )
	{
		$aHistoryReason = $this->gethistoryreason( );
		$aData['time'] = time( );
		$aData['type'] = $aHistoryReason[$aData['reason']]['type'];
		if(empty($aData['describe'])){
			$aData['reason_describe'] = $aHistoryReason[$aData['reason']]['describe'];
		}
		else $aData['reason_describe']=$aData['describe'];
		$rRs = $this->db->query( "SELECT * FROM sdb_point_history WHERE 0=1" );
		$sSql = $this->db->getinsertsql( $rRs, $aData );
		$this->db->query( $sSql );
	}
	
	function getpointhistorylist( $userId )
	{
		$aData = $this->db->select( "SELECT time, reason, reason_describe, point, related_id FROM sdb_point_history WHERE member_id=".$userId." ORDER BY time DESC" );
		$aHistoryReason = $this->gethistoryreason( );
		if ( $aData )
		{
			foreach ( $aData as $k => $aItem )
			{
				if(empty($aData[$k]['reason_describe'])){
					$aData[$k]['describe'] = $aHistoryReason[$aItem['reason']]['describe'];
				}
				else $aData[$k]['describe'] = $aData[$k]['reason_describe'];
			}
		}
		return $aData;
	}
	
	function getfrontpointhistorylist( $userId, $nPage )
	{
		$aData = $this->db->select_f( "SELECT time, reason,reason_describe, point, related_id FROM sdb_point_history WHERE member_id=".$userId." ORDER BY time DESC", $nPage, PERPAGE );
		$aHistoryReason = $this->gethistoryreason( );
		if ( $aData['data'] )
		{
			foreach ( $aData['data'] as $k => $aItem )
			{
				if(empty($aData['data'][$k]['reason_describe'])){
				$aData['data'][$k]['describe'] = $aHistoryReason[$aItem['reason']]['describe'];
				}
				else $aData['data'][$k]['describe'] = $aData['data'][$k]['reason_describe'];
			}
		}
		return $aData;
	}
	

}

?>